package com.heima.jobs.config;

import com.xxl.job.core.executor.impl.XxlJobSpringExecutor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class XxlJobConfig {
    // 调度中心地址
    @Value("${xxljob.admin.addresses}")
    private String adminAddresses;
    // 注册 执行器名称
    @Value("${xxljob.executor.appname}")
    private String appName;
    // 当前执行器端口
    @Value("${xxljob.executor.port}")
    private int port;
    // 日志文件输出路径
//    @Value("${xxljob.executor.logPath}")
//    private String logPath;
//    @Value("${xxljob.executor.address}")
//    private String address;

    @Bean
    public XxlJobSpringExecutor xxlJobSpringExecutor(){
        XxlJobSpringExecutor xxlJobSpringExecutor = new XxlJobSpringExecutor();
        xxlJobSpringExecutor.setAdminAddresses(adminAddresses);
        xxlJobSpringExecutor.setAppname(appName);
        xxlJobSpringExecutor.setPort(port);
        xxlJobSpringExecutor.setLogRetentionDays(30);
//        xxlJobSpringExecutor.setLogPath(logPath);
//        xxlJobSpringExecutor.setAddress(address);
        return xxlJobSpringExecutor;
    }
}
